﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TravelLink.WebModel;

namespace TravelLink.WebApp.UserControl.Member {
    public partial class UC_Member_EditRegisterInfo : ControlBase {
        protected void Page_Load(object sender, EventArgs e) {

        }

        protected void btnSavePassword_Click(object sender, ImageClickEventArgs e) {
            if (!string.IsNullOrEmpty(this.txtCurrentPassword.Text) && !string.IsNullOrEmpty(this.txtNewPassword.Text) && !string.IsNullOrEmpty(this.txtConfirmPassword.Text) && this.txtCurrentPassword.Text.Trim().Equals(this.CurrentUser.DBUser.Password, StringComparison.CurrentCultureIgnoreCase)) {
                var userEntity = this.DB.TL_User.Where(u => u.UserCode == this.CurrentUser.DBUser.UserCode).FirstOrDefault();
                if (userEntity != null) {
                    userEntity.Password = this.txtConfirmPassword.Text;
                    this.CurrentUser.DBUser = userEntity;
                    UserStoreFacade.Update(this.CurrentUser);
                    this.DB.SubmitChanges();
                    RegisteScript("alert('密码保存成功');");
                }
            }
        }

        protected void btnSaveMobile_Click(object sender, ImageClickEventArgs e) {
            if (!string.IsNullOrEmpty(this.txtMobile.Text)) {
                var userEntity = this.DB.TL_User.Where(u => u.UserCode == this.CurrentUser.DBUser.UserCode).FirstOrDefault();
                if (userEntity != null) {
                    userEntity.Mobile = this.txtMobile.Text;
                    this.CurrentUser.DBUser = userEntity;
                    UserStoreFacade.Update(this.CurrentUser);
                    this.DB.SubmitChanges();
                    RegisteScript("alert('手机号码保存成功');");
                }
            }
        }
    }
}